<template>
  <div v-if="loading" style="position: fixed; width:100%; height:100%; z-index: 99999; background:white; top:0; left:0;">
    <div style="text-align: center; padding-top: 30% ">正在获取钉钉授权登陆中...</div>
  </div>
</template>

<script>
  import dingMixin from  '@/mixins/ding'

  export default {
    data () {
      return {
        loading: false
      }
    },
    props:{
    },
    mixins: [dingMixin],
    methods: {
      login(){
        return new Promise((resolve, reject) => {
        if(this.isExpire()) {
              this.loading = true
              this.getDingConfig().then(config => {
                this.dingConfig = config;
                this.dingLogin(config.corpId, () => {
                  this.loading = false
                  return resolve(true);
                });
              })
          }else{
            return resolve(true);
          }
        })
      },
      isExpire(){
        if(this.lastLoginTime == null || new Date().getTime() > this.lastLoginTime + 1000 * 3600 * 1.5){
          this.lastLoginTime = new Date().getTime()
          return true;
        }
        return false;
      }
    },
    computed: {
      lastLoginTime:{
        get () { return this.$store.state.user.lastLoginTime  },
        set (val) { this.$store.commit('user/updateLastLoginTime', val)  }
      }
    }
  }
</script>
<style scoped>

</style>
